package com.atguigu.cmsservice.controller;


import com.atguigu.cmsservice.entity.CrmBanner;
import com.atguigu.cmsservice.service.CrmBannerService;
import com.atguigu.common.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-04-18
 */
@RestController
@RequestMapping("/cmsservice/banneradmin")
//@CrossOrigin
public class CrmBannerAdminController {

    @Autowired
    private CrmBannerService bannerService;

    //banner分页查询
    @GetMapping("getBannerAminList/{page}/{limit}")
    public R getBannerAminList(@PathVariable long page,@PathVariable long limit) {
        Page<CrmBanner> pageBanner = new Page<>(page,limit);
        bannerService.page(pageBanner,null);
        return R.ok().data("total",pageBanner.getTotal()).data("rows",pageBanner.getRecords());
    }

    //banner添加
    @PostMapping("addBanner")
    public R addBanner(@RequestBody CrmBanner banner) {
        bannerService.save(banner);
        return R.ok();
    }

    //banner删除
    @DeleteMapping("{bannerId}")
    public R deleteBanner(@PathVariable String bannerId) {
        bannerService.removeById(bannerId);
        return R.ok();
    }

    //根据id查询banner信息
    //修改banner信息
}

